package com.sl.biz.modular.job.dao.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.domain.request.JobPageParamRpcRequest;
import com.sl.biz.modular.job.dao.entity.JobConfigDO;
import com.sl.biz.modular.job.dao.mapper.JobConfigMapper;
import com.sl.biz.modular.job.dao.service.JobConfigDaoService;
import com.sl.common.page.CommonPageRequest;
import com.sl.common.page.PageList;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class JobConfigDaoServiceImpl extends ServiceImpl<JobConfigMapper, JobConfigDO> implements JobConfigDaoService {
    @Override
    public List<JobConfigDO> queryList(JobPageParamRpcRequest jobPageParamRpcRequest) {
        LambdaQueryWrapper<JobConfigDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.eq(StrUtil.isNotBlank(jobPageParamRpcRequest.getGroupCode()), JobConfigDO::getGroupCode, jobPageParamRpcRequest.getGroupCode());

        lambdaQueryWrapper.like(StrUtil.isNotBlank(jobPageParamRpcRequest.getSearchKey()),JobConfigDO::getJobName, jobPageParamRpcRequest.getSearchKey());

        lambdaQueryWrapper.eq(StrUtil.isNotBlank(jobPageParamRpcRequest.getJobStatus()), JobConfigDO::getState, jobPageParamRpcRequest.getJobStatus());
        Page<JobConfigDO> objectPage = CommonPageRequest.defaultPage(jobPageParamRpcRequest);
        Page<JobConfigDO> page = this.page(objectPage, lambdaQueryWrapper);
        return PageList.valueOf(page);
    }
}
